File: matlabfindpeaks.c

    1   /*
    2    * File: matlabfindpeaks.c
    3    *
    4    * MATLAB Coder version            : 3.1
    5    * C/C++ source code generated on  : 22-Apr-2021 15:09:40
    6    */
    7   
    8   /* Include Files */
    9   #include "rt_nonfinite.h"
   10   #include "matlabfindpeaks.h"
   11   #include "matlabfindpeaks_emxutil.h"
   12   #include "findpeaks.h"
   13   #include "eml_setop.h"
   14   
   15   /* Function Definitions */
   16   
   17   /*
   18    * Arguments    : const double Yin[52000]
   19    *                double minpeakhight
   20    *                int minpeakdistance
   21    *                emxArray_real_T *peaks
   22    *                emxArray_real_T *locs
   23    * Return Type  : void
   24    */
   25   void matlabfindpeaks(const double Yin[52000], double minpeakhight, int
   26                        minpeakdistance, emxArray_real_T *peaks, emxArray_real_T
   27                        *locs)
   28   {
   29     static double y[52000];
   30     emxArray_real_T *iPk;
   31     emxArray_real_T *iFinite;
   32     emxArray_real_T *iInflect;
   33     emxArray_real_T *iInf;
   34     double minH;
   35     int minD;
   36     int i0;
   37     int loop_ub;
   38     emxArray_real_T *idx;
   39     emxArray_real_T *b_iPk;
   40     emxArray_int32_T *ia;
   41     emxArray_int32_T *ib;
   42   
   43     /* matlabfindpeaks */
   44     memcpy(&y[0], &Yin[0], 52000U * sizeof(double));
   45     emxInit_real_T(&iPk, 1);
   46     emxInit_real_T(&iFinite, 1);
   47     emxInit_real_T(&iInflect, 1);
   48     emxInit_real_T(&iInf, 1);
   49     parse_inputs(minpeakhight, minpeakdistance, &minH, &minD);
   50     getAllPeaks(y, iFinite, iInf, iInflect);
   51     removePeaksBelowMinPeakHeight(y, iFinite, minH);
   52     i0 = iPk->size[0];
   53     iPk->size[0] = iFinite->size[0];
   54     emxEnsureCapacity((emxArray__common *)iPk, i0, (int)sizeof(double));
   55     loop_ub = iFinite->size[0];
   56     emxFree_real_T(&iInflect);
   57     for (i0 = 0; i0 < loop_ub; i0++) {
   58       iPk->data[i0] = iFinite->data[i0];
   59     }
   60   
   61     i0 = iFinite->size[0];
   62     iFinite->size[0] = iPk->size[0];
   63     emxEnsureCapacity((emxArray__common *)iFinite, i0, (int)sizeof(double));
   64     loop_ub = iPk->size[0];
   65     for (i0 = 0; i0 < loop_ub; i0++) {
   66       iFinite->data[i0] = iPk->data[i0];
   67     }
   68   
   69     removePeaksBelowThreshold(y, iFinite);
   70     i0 = iPk->size[0];
   71     iPk->size[0] = iFinite->size[0];
   72     emxEnsureCapacity((emxArray__common *)iPk, i0, (int)sizeof(double));
   73     loop_ub = iFinite->size[0];
   74     for (i0 = 0; i0 < loop_ub; i0++) {
   75       iPk->data[i0] = iFinite->data[i0];
   76     }
   77   
   78     emxFree_real_T(&iFinite);
   79     emxInit_real_T(&idx, 1);
   80     emxInit_real_T(&b_iPk, 1);
   81     emxInit_int32_T(&ia, 1);
   82     emxInit_int32_T(&ib, 1);
   83     do_vectors(iPk, iInf, b_iPk, ia, ib);
   84     c_findPeaksSeparatedByMoreThanM(y, b_iPk, minD, idx);
   85     keepAtMostNpPeaks(idx);
   86     i0 = iPk->size[0];
   87     iPk->size[0] = idx->size[0];
   88     emxEnsureCapacity((emxArray__common *)iPk, i0, (int)sizeof(double));
   89     loop_ub = idx->size[0];
   90     emxFree_int32_T(&ib);
   91     emxFree_int32_T(&ia);
   92     emxFree_real_T(&iInf);
   93     for (i0 = 0; i0 < loop_ub; i0++) {
   94       iPk->data[i0] = b_iPk->data[(int)idx->data[i0] - 1];
   95     }
   96   
   97     emxFree_real_T(&b_iPk);
   98     emxFree_real_T(&idx);
   99     i0 = peaks->size[0];
  100     peaks->size[0] = iPk->size[0];
  101     emxEnsureCapacity((emxArray__common *)peaks, i0, (int)sizeof(double));
  102     loop_ub = iPk->size[0];
  103     for (i0 = 0; i0 < loop_ub; i0++) {
  104       peaks->data[i0] = y[(int)iPk->data[i0] - 1];
  105     }
  106   
  107     i0 = locs->size[0];
  108     locs->size[0] = iPk->size[0];
  109     emxEnsureCapacity((emxArray__common *)locs, i0, (int)sizeof(double));
  110     loop_ub = iPk->size[0];
  111     for (i0 = 0; i0 < loop_ub; i0++) {
  112       locs->data[i0] = 1.0 + (double)((int)iPk->data[i0] - 1);
  113     }
  114   
  115     emxFree_real_T(&iPk);
  116   
  117     /* 寻峰及对应波长 */
  118   }
  119   
  120   /*
  121    * File trailer for matlabfindpeaks.c
  122    *
  123    * [EOF]
  124    */
  125